/*
 * SemanticAnalysisVisitor.h
 *
 *  Created on: Nov 23, 2010
 *      Author: dhovemey
 */

#ifndef SEMANTICANALYSISVISITOR_H_
#define SEMANTICANALYSISVISITOR_H_

#include <vector>
#include "fe/PreorderASTNodeVisitor.h"
class Exception;
class CompositeException;
class SymbolTable;

class SemanticAnalysisVisitor : public PreorderASTNodeVisitor {
private:
	SemanticAnalysisVisitor(const SemanticAnalysisVisitor &);
	SemanticAnalysisVisitor& operator=(const SemanticAnalysisVisitor &);

	typedef std::vector<Exception *> ExceptionList;

	ExceptionList m_exceptionList;
	SymbolTable *m_symtab;

public:
	SemanticAnalysisVisitor();
	virtual ~SemanticAnalysisVisitor();

	/**
	 * @return true if a semantic analysis error occurred, false otherwise
	 */
	bool error();

	/**
	 * @return a CompositeException containing all of the SemanticAnalysisExceptions
	 *         which occurred
	 */
	CompositeException *getException();

	virtual void visitClass(ASTNode * n);
	virtual void visitModule(ASTNode * n);

	virtual void visitVarRefExpr(ASTNode*);
	virtual void visitIntLiteralExpr(ASTNode*);
	virtual void visitBooleanLiteralExpr(ASTNode*);
	virtual void visitSymbolLiteralExpr(ASTNode*);
	virtual void visitStringLiteralExpr(ASTNode*);
	virtual void visitSelfRefExpr(ASTNode*);
	virtual void visitField(ASTNode*);
	virtual void visitVar(ASTNode*);
	virtual void visitImport(ASTNode*);
	virtual void visitStaticImport(ASTNode*);
	virtual void visitNilExpr(ASTNode*);

private:
	void handleException();
	SymbolTable *createClassOrModuleSymbolTable(ASTNode *n);
};

#endif /* SEMANTICANALYSISVISITOR_H_ */
